//前后缀运算符重载
#include <iostream>
#include <string.h>
#include <unistd.h>
using namespace std;

class Time
{
    public:
    int hour;
    int minute;
    int second;

    Time(int h=0, int m=0, int s=0):hour(h),minute(m),second(s){}

    //加法运算符操作函数重载（t1+t2）
    const Time operator+(const Time &r);

    //输出运算符操作函数重载（t << cout）
    ostream & operator<<(ostream &out);

    //前缀运算符函数重载
    Time & operator++();

    //后缀运算符函数重载
    const Time operator++(int);

    //显示时间
    void show();
    
};

ostream & Time:: operator<<(ostream &out)
{
    out << this->hour << ":" << this->minute << ":" << this->second << endl;   
    return out; 
}

const Time Time :: operator+(const Time &r)
{
    Time tmp;
    tmp.second = this->second +r.second;
    if(tmp.second >= 60)
    {
        tmp.minute++;
        tmp.second -= 60;
    }

    tmp.minute += this->minute + r.minute;
    if(tmp.minute >= 60)
    {
        tmp.hour++;
        tmp.minute -= 60;
    }

    tmp.hour += this->hour + r.hour;
    tmp.hour %= 24;
    return tmp;
}

void Time :: show()
{
    cout << hour << ":" << minute << ":" << second << endl;
}

//类外重载输出运输符（cout << t）
ostream &operator<<(ostream &out,Time &t)
{
    out.width(2);
    out.fill('0');
    out << t.hour << ":";

    out.width(2);
    out << t.minute << ":";

    out.width(2);
    out << t.second;
    return out;
}

 Time & Time :: operator++()  //前缀
 {
    second++;

    second = second>=60 ? (minute++,0) : second;
    minute = minute>=60 ? (hour++,0) : minute;
    hour %= 24;

    return *this;
 }

const Time Time :: operator++(int)
{
    Time tmp = *this;

    second++;

    second = second>=60 ? (minute++,0) : second;
    minute = minute>=60 ? (hour++,0) : minute;
    hour %= 24;

    return tmp;
}

int main(int argc, char const *argv[])
{
    Time t1(1,50,57);
    Time t2(0,20,43);

    // ++t1 = t2;
    // cout << t1 << endl;
    // cout << t2 << endl;

    // while(1)
    // {
    //     ++t1;
    //     cout << t1 << endl;
    //     sleep(1);
    // }

    while(1)
    {
        t1++;
        cout << t1 << endl;
        sleep(1);
    }
}

